package com.atguigu.mq.simple;

import com.atguigu.mq.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();

        //通过connection获取信道
        Channel channel = connection.createChannel();
        //声明队列
        String queue = "simple_queue";
        channel.queueDeclare(queue,true,false,false,null);

        String message = "hello rebbitmq";
        channel.basicPublish("",queue,null,message.getBytes());

        System.out.println("已发送消息:"+message);

        //关闭资源
        channel.close();
        connection.close();
    }
}
